package main

import (
	"os"
	"text/template"
)

func main() {

	type Service struct {
		Name    string
		Version string
		Port    string
		Command string
	}

	type Image struct {
		Name    string
		Version string
	}

	type Host struct {
		HostName string
		OS       string
	}

	type Application struct {
		Service
		Image
		Host
	}

	tmpl := `
version: '3'

services:
	{{.Service.Name}}_{{.Service.Version}}:
	container_name: {{.Service.Name}}_{{.Service.Version}}_{{.OS}}
	image: {{.Image.Name}}_{{.Image.Version}}:{{.OS}}
	hostname: {{.HostName}}
	restart: always
	command: {{.Command}} 
	expose:
		- "{{.Port}}"
	tty: true
	networks:
		extnetwork:
		ipv4_address: 172.21.124.2
	
networks:
	extnetwork:
	ipam:
		driver: default
		config:
		- subnet: 172.21.124.0/24
		gateway: 172.21.124.1
	`

	t, err := template.New("test").Parse(tmpl)
	if err != nil {
		panic(err)
	}

	data := new(Application)
	data.Service.Name = "openssh"
	data.Service.Version = "1"
	data.Service.Command = "ps"
	data.Image.Name = "openssh"
	data.Image.Version = "latest"
	data.Host.HostName = "centos"
	data.Host.OS = "centos"
	data.Service.Port = "22"
	err = t.Execute(os.Stdout, data)
	if err != nil {
		panic(err)
	}

}
